#ifndef VIEWWIDGET_H
#define VIEWWIDGET_H

#include <QWidget>
#include <QPainter>
#include <QAction>

#include <dynamicmodel.h>
#include <dynamicviewsettings.h>

class DynamicModel;
class ARSExecItem;
class UseCaseModel;
class UseCase;
class ServerModel;

typedef QList<QAction *> ActionList;

class ToolBarItem : public QObject
{
    Q_OBJECT

public:
    enum Type
    {
        Action,
        Widget
    };

    ToolBarItem(QAction * action = 0, QObject * parent = 0);
    virtual Type type() const = 0;

    QAction * action();
    void setAction(QAction * action);

private:
    QAction * m_action;
};

class ToolBarAction : public ToolBarItem
{
    Q_OBJECT

public:
    ToolBarAction(QAction * action, const QString & slot, QObject * parent = 0);

    Type type() const;
    QString slot() const;
    void setSlot(const QString & slot);

private:
    QString m_slot;
};

class ToolBarWidget : public ToolBarItem
{
    Q_OBJECT

public:
    ToolBarWidget(QWidget * widget, QObject * parent = 0);

    Type type() const;
    QWidget * widget();

private:
    QWidget * m_widget;
};

typedef QList<ToolBarItem *> ToolBarItemList;

class SettingsWidget : public QWidget
{
    Q_OBJECT

public:
    SettingsWidget(const QString & title = QString(), QWidget * parent = 0);

    QString title() const;
    void setTitle(const QString & title);
    bool isModified();

public slots:
    void setModified(bool modified = true);

signals:
    void midified();

private:
    QString m_title;
    bool m_isModified;
};

class AppEvent
{
public:
    enum Type
    {
        EventOpenFile
    };

    virtual Type type() const = 0;
};

class AppEventOpenFile : public AppEvent
{
public:
    AppEventOpenFile(const QString & path, const QDateTime date);

    Type type() const;
    QString path() const;
    QDateTime date() const;

private:
    QString m_path;
    QDateTime m_date;
};

class ViewWidget : public QWidget
{
    Q_OBJECT

public:
    enum ViewType
    {
        DummyView = 0,
        InProcessView = 1,
        DynamicModelView = 2,
        ProjectBayView = 3,
        ServerView = 4
    };

    ViewWidget(QWidget *parent = 0);
    virtual QString pluginName() const = 0;
    virtual void connectToolBarItems(const ToolBarItemList & items);
    virtual void disconnectToolBarItems(const ToolBarItemList & items);
    virtual void adjustToolbar(const ToolBarItemList & itemsList) const = 0;
};

class DynamicViewWidget : public ViewWidget
{
    Q_OBJECT

public:
    DynamicViewWidget(QWidget * parent = 0);
    virtual void setModel(DynamicModel * model) = 0;
    virtual void gotoItem(ARSExecItem * item);
    static void drawItem( const ARSExecItem * item, QPainter * painter, const QRect & rect, bool singleLine = false );
    static QRect drawField( QPainter * painter, const ARSExecItem * item, const QString & propertyName,
                            QRect rect, PropertyStyle * propertyStyle = 0 );
    static QSize itemVisualSize( const ARSExecItem * item, bool singleLine = false );

signals:
    virtual void openItem(ARSExecItem * item) = 0;

private:
    static const int SpacingInsideProperty = 6;
};

class UseCaseViewWidget : public ViewWidget
{
    Q_OBJECT

public:
    UseCaseViewWidget(QWidget *parent = 0);
    virtual void setModel(UseCaseModel * model) = 0;

signals:
    void needToLoadUseCase(UseCase * uc);
    void needToSaveUseCase(UseCase * uc);
};

class ServerViewWidget : public ViewWidget
{
    Q_OBJECT

public:
    ServerViewWidget(QWidget *parent = 0);

    virtual void setModel(ServerModel * model) = 0;
};

#endif // VIEWWIDGET_H
